/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.Server;

import com.kylingroup.Server.Thread.MainThread;
import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException;

/**
 *
 * @author kylin
 */
public class LinuxServer implements Daemon{
    private Thread mainThread;
    private MainThread r=null;
    @Override
    public void init(DaemonContext dc) throws DaemonInitException, Exception {
        String[] args = dc.getArguments();
        
        r=new MainThread();
        mainThread=new Thread(r);
        r.readyToStart();
        mainThread.start();
    }

    @Override
    public void start() throws Exception {
        mainThread.start();
    }

    @Override
    public void stop() throws Exception {
        r.stopFlag = true;
        try{
            mainThread.join(1000);
        }catch(InterruptedException e){
            System.err.println(e.getMessage());
            throw e;
        }
    }

    @Override
    public void destroy() {
        mainThread=null;
    }
}
